import React from 'react';
import { toJS } from 'mobx';
import { inject, observer } from 'mobx-react';
import { WeaErrorPage, WeaLocaleProvider, WeaRightMenu, WeaTools } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

import Top from './top';
import { ToolBar, PathSearch } from './toolBar';
import MoveDialog from './moveDialog';
import Table from './table';
import LookSharer from './lookSharer';
import Transportation from './transportation';
import IconView from './iconView';
import Share from './share';


@inject('netDiskStore')
@observer
class NetDisk extends React.Component {
   constructor(props) {
      super(props);
      const { rightMenu: { getRightMenuData } } = this.props.netDiskStore;
      getRightMenuData(); // 获取右键菜单数据
      this.searchParams(); // 解析参数，选定初始状态
   }

   componentDidMount() {
      const { rightMenu: { setRightMenuRef } } = this.props.netDiskStore;
      setRightMenuRef(this.rightMenuDom); // 获取右键菜单ref
   }

   // 分析参数
   searchParams = () => {
      const { changeTopSelect, changeShareTabSelect, changeView } = this.props.netDiskStore;
      let array = window.location.hash.split('#/main/document/netdisk?')[1].split('&');
      let param = {};
      array.forEach((i) => {
         let meta = i.split('=');
         param[meta[0]] = meta[1];
      });

      switch (true) {
         case param.hasOwnProperty('type'):
            if (param.type === 'shareMy') {
               changeTopSelect('share'); changeShareTabSelect('colleagueShare');
            } else if (param.type === 'myShare') {
               changeTopSelect('share'); changeShareTabSelect('myShare');
            }
         case param.hasOwnProperty('viewType'):
            if (param.viewType === 'list') {
               changeView('list');
            }
      }
   };


   render() {
      const { rightMenu, viewSettings } = this.props.netDiskStore;
      const { rightMenuOnClick } = rightMenu;
      return (
         <div className="wea-doc-netDisk" ref={e => this.mydom = e}>
            <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@vlwr3j`} datas={toJS(rightMenu.data)} ref={(el) => {
 this.rightMenuDom = el; 
}} width={135} onClick={rightMenuOnClick}>
               <Top ecId={`${this && this.props && this.props.ecId || ''}_Top@mnyb59`} className="Weareqtop-background" />
                  <ToolBar ecId={`${this && this.props && this.props.ecId || ''}_ToolBar@2pv3c0`} />
                  <PathSearch ecId={`${this && this.props && this.props.ecId || ''}_PathSearch@ews9u5`} />
                  {
                     viewSettings.type === 'list'
                        ?
                        <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@rcrd6f`} />
                        :
                        <IconView ecId={`${this && this.props && this.props.ecId || ''}_IconView@ghkgay`} />
                  }
               <MoveDialog ecId={`${this && this.props && this.props.ecId || ''}_MoveDialog@0ku8f6`} />
               <LookSharer ecId={`${this && this.props && this.props.ecId || ''}_LookSharer@r5hjze`} />
            </WeaRightMenu>
            <Share ecId={`${this && this.props && this.props.ecId || ''}_Share@are8jw`} />
            <Transportation ecId={`${this && this.props && this.props.ecId || ''}_Transportation@b5aztl`} />
         </div>
      );
   }
}


export default WeaTools.tryCatch(
   React,
   props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@e28pv3`} msg={props.error ? props.error : `${getLabel(383324, ' 对不起，该页面异常，请联系管理员 ')}！`} />,
   { error: '' },
)(NetDisk);

